package org.common.util;

import java.util.HashMap;

public class Result extends HashMap<String,Object> {
    private static final String CODE_TAG="code";
    private static final String MSG_TAG="message";
    private static final String DATA_TAG="data";

    public Result(){

    }
    public Result(int code,String message){
        super.put(CODE_TAG,code);
        super.put(MSG_TAG,message);
    }
    public Result(int code,String message,Object data){
        super.put(CODE_TAG,code);
        super.put(MSG_TAG,message);
        if (data!=null)
        {
            super.put(DATA_TAG, data);
        }
    }
    public static Result success(){
        return Result.success("操作成功");
    }
    public static Result success(Object data){
        return Result.success("操作成功",data);
    }
    public static Result success(String message){
        return new Result(HttpStatus.SUCCESS,message,null);
    }
    public static Result success(String message,Object data){
        return new Result(HttpStatus.SUCCESS,message,data);
    }
    public static Result warning(String message){
        return Result.warning(message,null);
    }
    public static Result warning(String message,Object data){
        return new Result(HttpStatus.WARN,message,data);
    }
    public static Result error(){
        return Result.error("操作失败!");
    }
    public static Result error(String message){
        return Result.error(message,null);
    }
    public static Result error(String message,Object data){
        return  new Result(HttpStatus.ERROR,message,data);
    }
    public static Result error(int code,String message){
        return new Result(code,message,null);
    }

    @Override
    public Result put(String key, Object value)
    {
        super.put(key, value);
        return this;
    }
}
